package com.example.controller.admin;

import com.example.common.Result;
import com.example.entity.DTO.MajorDetailDTO;
import com.example.entity.Major;
import com.example.service.admin.MajorService;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/admin")
public class MajorController {
    @Resource
    private MajorService majorService;

    /**
     * 获取全部专业详细信息
     */
    @GetMapping("/selectAllMajor")
    public Result selectAllMajor(@RequestParam(defaultValue = "") String majorName,
                                 @RequestParam(defaultValue = "") String deptName) {
        List<MajorDetailDTO> majorDetailDTOS = majorService.selectAllMajor(majorName, deptName);
        return Result.success(majorDetailDTOS);
    }

    /**
     * 根据名称获取专业
     */
    @GetMapping("/selectMajor")
    public Result selectMajor(@RequestParam String name) {
        Major major = majorService.selectMajor(name);
        return Result.success(major);
    }

    /**
     * 添加专业
     */
    @PostMapping("/addMajor")
    public Result addMajor(@RequestBody Major major) {
        majorService.addMajor(major);
        return Result.success();
    }

    /**
     * 更新专业信息
     */
    @PutMapping("/updateMajor")
    public Result updateMajor(@RequestBody Major major) {
        majorService.updateMajor(major);
        return Result.success();
    }

    /**
     * 删除专业
     */
    @DeleteMapping("/deleteMajor/{id}")
    public Result deleteMajor(@PathVariable Integer id) {
        majorService.deleteMajor(id);
        return Result.success();
    }
}
